package ysm.controller.admin;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

import ysm.entity.User;
import ysm.service.UserService;
import ysm.tools.ReadExcel;

@RestController
@RequestMapping("/public")
public class BulkRegisterController {
	
	@Autowired
	private ReadExcel readExcel;
	
	@Autowired
	private UserService userService;

	@RequestMapping("/bulkRegister")
	public void bulkRegister(String filePath) {
		try {
			List<String> list = readExcel.readStudent(filePath);
			for(String item: list) {
				User user = new User();
				user.setUsername(item);
				user.setPassword(item.substring(item.length()-6, item.length()));
				userService.addUser(user);
			}
		} catch (IOException e) { 
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
